﻿namespace Legend.Core.Tests
{
    using System;
    using System.Collections.Generic;
    using NUnit.Framework;

    [TestFixture]
    public class RangeTests
    {
        [Test]
        public void Should_have_lower_bound_set_from_constructor()
        {
            // Arrange
            var range = new Range<int>(1, 1);

            // Act, Asert
            Assert.That(range.LowerBound, Is.EqualTo(1));
        }

        [Test]
        public void Should_have_upper_bound_set_from_constructor()
        {
            // Arrange

            // Act
            var range = new Range<int>(2, 2);

            // Assert
            Assert.That(range.UpperBound, Is.EqualTo(2));
        }

        [Test]
        public void Should_fail_when_lower_bound_is_greater_than_upper_bound()
        {
            // Arrange

            // Act

            // Assert
            Assert.That(() => { new Range<int>(2, 1); }, Throws.InstanceOf<ArgumentException>());
        }

        [TestCase(1, 3, 2, Result = true)]
        [TestCase(1, 2, 0, Result = false)]
        [TestCase(1, 2, 3, Result = false)]
        [TestCase(1, 2, 1, Result = true)]
        [TestCase(1, 2, 2, Result = true)]
        public bool Should_give_correct_result_when_asking_if_a_value_is_in_range(int lowerBound, int upperBound, int value)
        {
            // Arrange
            var range = new Range<int>(lowerBound, upperBound);

            // Act

            // Assert
            return range.IsInRange(value);
        }

        private class StringLengthComparer
            : IComparer<string>
        {
            public int Compare(string x, string y)
            {
                return (x ?? string.Empty).Length.CompareTo((y ?? string.Empty).Length);
            }
        }
    }
}
